<template>
  <!--   筛选列表-->
  <div class="wrapper">
    <div
      v-loading="loading"
      element-loading-text="拼命加载中"
      element-loading-spinner="el-icon-loading"
      element-loading-background="rgba(255, 255, 255, 0.8)"
      class="main-message"
    >
      <!--      按钮区域-->
      <div class="btn-layout">
        <div>
          <el-button size="mini" type="primary" @click="ExcelPrescPatList">导出筛选清单</el-button>
          <!--          <el-button size="mini" type="primary">清空自动点评</el-button>-->
          <!--          <el-button size="mini" type="primary">恢复自动点评</el-button>-->
          <el-button size="mini" type="primary" @click="SaveTaskList">保存任务</el-button>
        </div>
      </div>
      <div class="card-layout">
        <el-scrollbar ref="elbar" style="width:2000px;height:600px">
          <Bluetable
            ref="blueTable"
            :t-head="presc_patListHead"
            :t-data="presc_patList"
            @operateClick="operateClickprescPatList"
          />
          <pagination
            v-show="!isChouyang"
            :total="pageInfo.total"
            :page.sync="pageInfo.pagenum"
            :limit.sync="pageInfo.pagesize"
            @pagination="pageGetPrescPatList"
          />
        </el-scrollbar>

      </div>
    </div>
    <div class="seek_pop">
      <el-dialog
        title="查询医嘱信息"
        :visible.sync="dialogVisible"
        width="90%"
      >
        <div class="seek_form clear">
          <div class="seek_factor fl">
            <span class="seek_text" title="住院号">住院号</span>
            <span class="seek_val" :title="info.inpno">{{ info.inpno }}</span>
          </div>
          <div class="seek_factor fl">
            <span class="seek_text" title="就诊科室">就诊科室</span>
            <span class="seek_val" :title="info.deptname">{{ info.deptname }}</span>
          </div>
          <div class="seek_factor fl">
            <span class="seek_text" title="就诊日期">就诊日期</span>
            <span class="seek_val" :title="info.ordertime">{{ info.ordertime }}</span>
          </div>
          <div class="seek_factor fl">
            <span class="seek_text" title="就诊医生">就诊医生</span>
            <span class="seek_val" :title="info.doctorname">{{ info.doctorname }}</span>
          </div>
          <div class="seek_factor fl">
            <span class="seek_text" title="病人姓名">病人姓名</span>
            <span class="seek_val" :title="info.patientname">{{ info.patientname }}</span>
          </div>
          <div class="seek_factor fl">
            <span class="seek_text" title="性别">性别</span>
            <span class="seek_val" :title="info.sex">{{ info.sex }}</span>
          </div>
          <div class="seek_factor fl">
            <span class="seek_text" title="年龄">年龄</span>
            <span class="seek_val" :title="info.age">{{ info.age }}</span>
          </div>
          <div class="seek_factor fl">
            <span class="seek_text" title="身份证号码">身份证号码</span>
            <span class="seek_val" :title="info.idcard">{{ info.idcard }}</span>
          </div>
          <div class="seek_factor fl">
            <span class="seek_text" title="出生日期">出生日期</span>
            <span class="seek_val" :title="info.birthdate">{{ info.birthdate }}</span>
          </div>
          <div class="seek_factor fl">
            <span class="seek_text" title="联系电话">联系电话</span>
            <span class="seek_val" :title="info.telephone">{{ info.telephone }}</span>
          </div>
          <div class="seek_factor fl">
            <span class="seek_text" title="费别">费别</span>
            <span class="seek_val" :title="info.payclass">{{ info.payclass }}</span>
          </div>
          <div class="seek_factor fl">
            <span class="seek_text" title="临床诊断">临床诊断</span>
            <span class="seek_val" :title="info.disname">{{ info.disname }}</span>
          </div>
        </div>
        <div class="seek_tabs">
          <el-tabs v-model="activeName" @tab-click="handleClick">
            <el-tab-pane :label="'医嘱信息'" name="yzxx">
              <div style="display: flex;padding-bottom: 5px;align-items: center">
                <span style="padding-right: 10px">药品筛选</span>
                <el-input v-model="drugnameInput" style="width: 200px" placeholder="请输入药品" />
                <el-select v-model="ordertypeSelect" style="padding: 0 20px" clearable placeholder="请选择">
                  <el-option
                    v-for="item in ordertype"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>

                <el-select v-model="ordertypeListSelect" clearable placeholder="请选择">
                  <el-option
                    v-for="item in ordertypeList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </div>
              <el-scrollbar ref="elbar" style="height:300px">
                <Bluetable :t-head="getOrdersHead" :t-data="getOrders" @operateClick="operateClickOrders" />
              </el-scrollbar>
            </el-tab-pane>
            <el-tab-pane :label="'检查信息'" name="jcxx">
              <el-scrollbar ref="elbar" style="height:350px">
                <div class="twoTable">
                  <Bluetable :t-head="getExamHead" :t-data="getExam" />
                </div>
              </el-scrollbar>
            </el-tab-pane>
            <el-tab-pane :label="'检验信息'" name="jyxx">
              <el-scrollbar ref="elbar" style="height:350px">
                <Bluetable :t-head="getLabHead" :t-data="getLab" />
              </el-scrollbar>
            </el-tab-pane>
            <el-tab-pane :label="'费用信息'" name="fyxx">
              <el-scrollbar ref="elbar" style="height:350px">
                <Bluetable
                  :t-head="getCostHead"
                  :t-data="getCost"
                />
              </el-scrollbar>
            </el-tab-pane>
          </el-tabs>
        </div>
        <div class="card_result">
          <card>
            <div slot="cardHeader">点评结果</div>
            <div slot="cardBody">
              <div class="seek_other">
                <div class="btns">
                  <div style="display: flex;">
                    <el-button style="margin-right: 5px" type="primary" size="mini" @click="setAllgetProblemList">合理/不合理</el-button>
                    <el-button style="margin-right: 5px" type="success" size="mini" @click="setProblemListsuccess">合理</el-button>
                    <el-button style="margin-right: 5px" type="danger" size="mini" @click="setProblemListdanger">不合理</el-button>
                  </div>
                  <div style="display: flex">
                    <el-button style="margin-right: 5px" type="primary" size="mini" @click="showAddVisibleFlag">新增问题</el-button>
                    <el-button type="danger" size="mini" @click="DeleteProblem">清空点评</el-button>
                  </div>
                </div>
                <div class="tabs">
                  <el-scrollbar ref="elbar" style="height:300px">
                    <Bluetable
                      :t-head="getProblemListHead"
                      :t-data="getProblemList"
                      @operateClick="operateClickProblem"
                    />
                  </el-scrollbar>
                </div>
              </div></div>
          </card>
        </div>
      </el-dialog>
      <el-dialog
        title="问题"
        :visible.sync="addVisible"
        width="70%"
        @close="closeAddVisible"
      >
        <el-form :model="addInfo">
          <el-form-item label="问题药品" :label-width="formLabelWidth">
            <el-input v-model="addInfo.Drugname" autocomplete="off" />
          </el-form-item>
          <el-form-item label="点评点" :label-width="formLabelWidth">
            <el-scrollbar ref="elbar" style="height:300px">
              <Bluetable
                ref="ref"
                :t-head="getRulesHead"
                :t-data="getRules"
                @selectionChange="selectionChange"
              />
            </el-scrollbar>
          </el-form-item>
          <el-form-item label="已选点评点" :label-width="formLabelWidth">
            <el-input v-model="addInfo.selectInfo" :disabled="true" type="textarea" />
          </el-form-item>
          <el-form-item label="用药分析和建议" :label-width="formLabelWidth">
            <el-input v-model="addInfo.ManageviewTemp" type="textarea" />
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="closeAddVisible">取 消</el-button>
          <el-button v-if="isAddFlag==='新增'" type="primary" @click="GetCommentsID">保 存</el-button>
          <el-button v-if="isAddFlag==='修改'" type="primary" @click="UpProblemList">修 改</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import { GetPatientInpComment,
  GetOrdersInpComment,
  GetLabInpComment,
  GetExamInpComment,
  GetCostInpComment,
  GetProblemListInpComment,
  DeleteProblem,
  GetRules,
  GetCommentsID,
  SaveProblemList,
  UpProblemList,
  DeleteProblemList,
  GetOrdersPatList,
  ExcelPrescPatList, SaveInpTaskList
} from '@/api/prc17212'
import Card from '../childComps/card/Card'
export default {
  name: 'OutPrescPatList',
  components: { Card },
  data() {
    return {
      loading: true,
      UserName: '123',
      UserCode: '123',
      // 筛选条件
      JsonValueTemp: {},
      // 筛选结果
      presc_patList: [],
      fileObj: {},
      pageInfo: {
        pagesize: 10,
        pagenum: 1,
        total: 0
      },
      presc_patListHead: [{ operate: ['查看'], label: '操作', link: true, width: '100px' },
        { prop: 'inpno', label: '住院号' },
        { prop: 'patientname', label: '姓名' },
        { prop: 'sex', label: '性别' },
        { prop: 'age', label: '年龄' },
        { prop: 'deptname', label: '科室' },
        { prop: 'doctorname', label: '医生' },
        { prop: 'ordertime', label: '时间' },
        { prop: 'diseasename', label: '临床诊断', width: '300px' },
        { prop: 'payclass', label: '费别' },
        { prop: 'commentuser', label: '点评人' },
        { prop: 'commentresult', label: '点评结果' },
        { prop: 'commenttime', label: '点评时间' },
        { prop: 'commentsname', label: '点评结果' },
        { prop: 'ruleid', label: '点评点' },
        { prop: 'commentmode', label: '点评类型' },
        { prop: 'commentdrug', label: '点评药品' },
        { prop: 'drugtypecount', label: '药品种类' },
        { prop: 'antitypecount', label: '抗菌药种类' },
        { prop: 'specialantitypecount', label: '特抗种类' },
        { prop: 'injection', label: '注射剂' },
        { prop: 'basictypecount', label: '基药' },
        { prop: 'cost', label: '药品费用' },
        { prop: 'anticost', label: '抗菌药费用' },
        { prop: 'basecost', label: '基药费别' }
      ],
      dialogVisible: false,
      activeName: 'yzxx',
      // 弹窗信息
      info: {
        inpno: '', // 门诊号
        deptname: '', // 科室
        doctorname: '', //	医生
        ordertime: '', //	时间
        patientname: '', // 病人
        sex: '', //	性别
        age: '', //	年龄seek_pop
        idcard: '', //	身份证
        payclass: '', //	费别
        birthdate: '', //	生日
        telephone: '', // 电话
        disname: ''//	诊断
      },
      // 医嘱信息
      getOrders: [],
      getOrdersHead: [{ operate: ['新增问题'], label: '操作', link: true, width: '100px' },
        { prop: 'ordername', label: '药品名称', width: '150px' },
        { prop: 'drugform', label: '剂型' },
        { prop: 'drugspec', label: '规格' },
        { prop: 'routename', label: '给药途径' },
        { prop: 'singledose', label: '单次剂量' },
        { prop: 'doseunit', label: '给药途径' },
        { prop: 'freq', label: '频次' },
        { prop: 'numunit', label: '数量单位' },
        { prop: 'num', label: '数量' },
        { prop: 'cost', label: '费用' },
        { prop: 'doctorname', label: '医生' },
        { prop: 'purpose', label: '备注' },
        { prop: 'startdatetime', label: '开始时间', width: '90px' },
        { prop: 'deptname', label: '科室' },
        { prop: 'prescno', label: '处方号' },
        { prop: 'anti', label: '抗菌药物' },
        { prop: 'grouptag', label: '分组' }
      ],
      // 检查信息
      getExam: [],
      getExamHead: [
        { prop: 'examcode', label: '检查编码' },
        { prop: 'examname', label: '检查名称' },
        { prop: 'doctorname', label: '医生编码' },
        { prop: 'deptname', label: '医生' },
        { prop: 'bodypart', label: '部位' },
        { prop: 'reporttime', label: '检查时间' },
        { prop: 'examresult', label: '检查结果' }
      ],
      // 检验信息
      getLab: [],
      getLabHead: [
        { prop: 'requestno', label: '申请号' },
        { prop: 'itemname', label: '检验名称' },
        { prop: 'samplingtime', label: '采样时间' },
        { prop: 'reporttime', label: '报告时间' }
      ],
      // 费用
      getCost: [],
      getCostHead: [
        { prop: 'itemcode', label: '药品编码' },
        { prop: 'itemname', label: '药品名称' },
        { prop: 'drugform', label: '药品剂型' },
        { prop: 'drugspec', label: '药品规格' },
        { prop: 'drugsccj', label: '厂家' },
        { prop: 'cost', label: '费用' },
        { prop: 'itemnum', label: '数量' },
        { prop: 'itemunit', label: '单位' },
        { prop: 'itemcost', label: '药品费用' },
        { prop: 'costtime', label: '收费时间' },
        { prop: 'doctorname', label: '医生' },
        { prop: 'deptname', label: '科室' },
        { prop: 'pharmacists', label: '调配药师' },
        { prop: 'pharmacists_复制', label: '发药药师' }
      ],
      // 问题
      getProblemList: [],
      allgetProblemList: [],
      // 合理
      getProblemListsuccess: [],
      // 不合理
      getProblemListdanger: [],
      getProblemListHead: [
        { operate: ['修改', '删除'], label: '操作', link: true, width: '100px' },
        { prop: 'comments_result', label: '点评结果' },
        { prop: 'id', label: 'id' },
        { prop: 'patient_id', label: '病人id' },
        { prop: 'comments_user', label: '点评人编码' },
        { prop: 'comments_type', label: '类别' },
        { prop: 'datetime', label: '时间' },
        { prop: 'clinic_no', label: '门诊号' },
        { prop: 'presc_no', label: '处方号' },
        { prop: 'comments_mode', label: '点评类型' },
        { prop: 'ruleid', label: '点评点' },
        { prop: 'is_use', label: '是否开启' },
        { prop: 'commentsname', label: '点评内容', width: '300px' },
        { prop: 'drugname', label: '药品' },
        { prop: 'manageview', label: '意见描述', width: '300px' },
        { prop: 'hospital_code', label: '医院编码' }
      ],
      patientInfo: {},
      nextval: null, // 新增问题id
      Id: null, // 删除问题id
      problemInfoVisible: false,
      problemInfo: {
        RuleId: '',
        DrugName: '',
        CommentsName: '',
        Id: ''
      },
      // where的筛选信息
      whereInfo: '',
      drugnameInput: '',
      drugnameInputHandler: '',
      ordertypeSelect: '',
      ordertype: [
        { value: "o.ordertype = '1'", label: '药品医嘱' },
        { value: "o.ordertype <>'1'", label: '非药品医嘱' }
      ],
      ordertypeListSelect: '',
      ordertypeList: [
        { value: "o.ordertype = '1'", label: '全部药品医嘱' },
        { value: "d.anti = '1'", label: '抗菌药' },
        { value: "d.drugtype = '2'", label: '中药饮片' },
        { value: "d.drugtype = '1'", label: '中成药' },
        { value: "(d.basedrug = '1' or d.is_basedrug_p = '1')", label: '基本药物' },
        { value: "d.is_stimulant = '1'", label: '兴奋剂' },
        { value: "d.jdmtype = '1'", label: '精一药品' },
        { value: "d.jdmtype = '2'", label: '精二药品' },
        { value: "d.jdmtype = '3'", label: '毒性药品' },
        { value: "d.jdmtype = '4'", label: '麻醉药' },
        { value: "d.is_sugarmed = '1'", label: '糖皮质激素' },
        { value: "d.is_bloodmed = '1'", label: '血液制品' },
        { value: "d.is_tumours_drug = '1'", label: '肿瘤用药' },
        { value: "d.drugname like '万古霉素'", label: '万古霉素' }
      ],
      // 新增点评弹窗
      addVisible: false,
      // 新增点评信息
      addInfo: {
        Drugname: '',
        RuleInfo: [],
        id: '',
        RuleInfoId: '',
        RuleInfoIs_Use: '',
        RuleInfoComments_Name: '',
        selectInfo: '',
        ManageviewTemp: '',
        Manageview: ''
      },
      formLabelWidth: '120px',
      // 点评点信息
      getRules: [],
      getRulesHead: [{
        selection: true
      }, {
        prop: 'commentsid',
        label: '点评点',
        width: '75px'
      }, {
        prop: 'commentsname',
        label: '点评点内容'
      }],
      isAddFlag: '新增',
      // 抽样 true抽样，false不抽样
      isChouyang: false
    }
  },
  watch: {
    drugnameInput: {
      handler: function(val, oldVal) {
        if (val === '') {
          this.drugnameInputHandler = ''
        } else {
          this.drugnameInputHandler = "d.drugname like '%" + val + "%'"
        }
        this.whereInfoChange()
      },
      deep: true
    },
    ordertypeSelect: {
      handler: function(val, oldVal) {
        if (val === null) {
          this.ordertypeSelect = ''
        }
        this.whereInfoChange()
      },
      deep: true
    },
    ordertypeListSelect: {
      handler: function(val, oldVal) {
        if (val === null) {
          this.ordertypeListSelect = ''
        }
        this.whereInfoChange()
      },
      deep: true
    },
    'addInfo.RuleInfoId': {
      handler: function(val, oldVal) {
        const RuleInfoItem = []
        for (var i = 0; i < this.RuleInfo.length; i++) {
          RuleInfoItem[i] = this.RuleInfo[i].commentsid + ' ' + this.RuleInfo[i].commentsname
        }
        this.addInfo.selectInfo = RuleInfoItem.join(',')
        this.addInfo.Manageview = this.addInfo.ManageviewTemp + ',' + this.addInfo.selectInfo
      },
      deep: true
    },
    'addInfo.ManageviewTemp': {
      handler: function(val, oldVal) {
        this.addInfo.Manageview = val + ',' + this.addInfo.selectInfo
      },
      deep: true
    }

  },

  // activated() {
  //   const userInfo = localStorage.getItem('user')
  //   this.UserCode = JSON.parse(userInfo).user_no
  //   this.UserName = JSON.parse(userInfo).user_name
  //   // this.presc_patList = this.$route.query.presc_patList
  //   this.JsonValueTemp = this.$route.query.JsonValueTemp
  //   console.log(this.JsonValueTemp)
  //   this.GetPrescPatList()
  // },
  mounted() {
    this.loading = true
    const userInfo = localStorage.getItem('user')
    this.UserCode = JSON.parse(userInfo).user_no
    this.UserName = JSON.parse(userInfo).user_name
    // this.presc_patList = this.$route.query.presc_patList
    this.JsonValueTemp = this.$route.query.JsonValueTemp
    this.GetPrescPatList()
  },
  methods: {

    // 下载表格
    async ExcelPrescPatList() {
      // 参数：筛选结果 + 路径
      const tempJson = this.fileObj
      tempJson.file = 'd:/demo.xls'
      const res = await ExcelPrescPatList(tempJson)
      // res.href,是接口返回的打开连接
      window.open('http://' + res.data, '_blank')
    },

    async SaveTaskList() {
      const tempJson = this.fileObj
      tempJson.username = this.UserName
      tempJson.userid = this.UserCode
      const res = await SaveInpTaskList(tempJson)
      if (res.code === 200) {
        this.$message({
          message: '保存成功',
          type: 'success'
        })
      } else {
        this.$message.error('保存失败')
      }
    },

    async GetPrescPatList() {
      this.loading = true
      await GetOrdersPatList({
        JsonValue: this.JsonValueTemp,
        pagesize: this.pageInfo.pagesize,
        pagenum: this.pageInfo.pagenum
      }).then(res => {
        console.log(res)
        if (res.code === 200) {
          if (res.data.rows === undefined) {
            this.isChouyang = true
            this.presc_patList = res.data
            this.fileObj = {
              code: res.code,
              data: {
                rows: res.data
              },
              msg: res.msg
            }
          } else {
            this.isChouyang = false
            this.presc_patList = res.data.rows
            this.pageInfo.total = res.data.records
            this.fileObj = res
          }
          this.loading = false
        }
      }).catch(err => {
        console.log(err)
      })
    },

    pageGetPrescPatList(type) {
      this.pageInfo.pagenum = type.page
      this.pageInfo.pagesize = type.limit
      this.GetPrescPatList()
    },
    // 筛选结果 查看
    operateClickprescPatList(val, row) {
      this.patientInfo = row
      console.log(row)
      console.log(this.patientInfo.patient_id)
      console.log(this.patientInfo.clinicno)
      this.GetPatient()
      this.GetOrders()
      this.GetLab()
      this.GetExam()
      this.GetCost()
      this.GetProblemList()
      this.showDialog()
    },
    handleClick(tab, event) {
      // console.log(tab, event);
    },
    showDialog() {
      this.dialogVisible = true
    },
    closeDialog() {
      this.dialogVisible = false
      this.info = {}
      this.getOrders = []
      this.getExam = []
      this.getLab = []
      this.getCost = []
    },
    // 获取病人
    async GetPatient() {
      await GetPatientInpComment({
        Patient_Id: this.patientInfo.patientid,
        Visit_Id: this.patientInfo.visitid,
        Hospital_Code: this.JsonValueTemp.Hospital_Code
      }).then(res => {
        console.log(res)
        if (res.code === 200) {
          this.info = res.data[0]
        }
      }).catch(err => {
        console.log(err)
      })
    },
    // 筛选条件改变
    whereInfoChange() {
      const tempWhere = {
        drugnameInput: this.drugnameInputHandler,
        ordertypeSelect: this.ordertypeSelect,
        ordertypeListSelect: this.ordertypeListSelect
      }
      this.whereInfo = ''
      for (var key in tempWhere) {
        if (tempWhere[key] !== '') {
          if (this.whereInfo === '') {
            this.whereInfo = tempWhere[key]
          } else {
            this.whereInfo += ' and ' + tempWhere[key]
          }
        }
      }
      this.GetOrders()
    },
    // 获取医嘱
    async GetOrders() {
      await GetOrdersInpComment({
        Patient_Id: this.patientInfo.patientid,
        Visit_Id: this.patientInfo.visitid,
        Presc_No: this.patientInfo.prescno,
        where: this.whereInfo,
        templateId: this.JsonValueTemp.templateId,
        Hospital_Code: this.JsonValueTemp.Hospital_Code
      }).then(res => {
        if (res.code === 200) {
          this.getOrders = res.data
        }
      }).catch(err => {
        console.log(err)
      })
    },
    operateClickOrders(val, row) {
      this.addInfo.Drugname = row.ordername
      this.isAddFlag = '新增'
      this.showAddVisible()
    },
    async GetLab() {
      await GetLabInpComment({
        Patient_Id: this.patientInfo.patientid,
        Visit_Id: this.patientInfo.visitid,
        Hospital_Code: this.JsonValueTemp.hospital_code
      }).then(res => {
        if (res.code === 200) {
          this.getLab = res.data
        }
      }).catch(err => {
        console.log(err)
      })
    },
    async GetExam() {
      await GetExamInpComment({
        Patient_Id: this.patientInfo.patientid,
        Visit_Id: this.patientInfo.visitid,
        Hospital_Code: this.JsonValueTemp.Hospital_Code
      }).then(res => {
        if (res.code === 200) {
          this.getExam = res.data
        }
      }).catch(err => {
        console.log(err)
      })
    },
    async GetCost() {
      await GetCostInpComment({
        Patient_Id: this.patientInfo.patientid,
        Visit_Id: this.patientInfo.visitid,
        templateId: this.JsonValueTemp.templateId,
        Hospital_Code: this.JsonValueTemp.Hospital_Code
      }).then(res => {
        if (res.code === 200) {
          this.getCost = res.data
        }
      }).catch(err => {
        console.log(err)
      })
    },
    // 获取问题
    async GetProblemList() {
      await GetProblemListInpComment({
        Patient_Id: this.patientInfo.patientid,
        Visit_Id: this.patientInfo.visitid,
        templateId: this.JsonValueTemp.templateId,
        Hospital_Code: this.JsonValueTemp.Hospital_Code
      }).then(res => {
        if (res.code === 200) {
          this.getProblemList = res.data
          this.allgetProblemList = this.getProblemList
          for (var i = 0; i < this.getProblemList.length; i++) {
            if (this.getProblemList[i].comments_result === '0') {
              this.getProblemListdanger[i] = this.getProblemList[i]
            } else if (this.getProblemList[i].comments_result === '1') {
              this.getProblemListsuccess[i] = this.getProblemList[i]
            }
          }
          // 合理数组1comments_result
          // 不合理数组0
        }
      }).catch(err => {
        console.log(err)
      })
    },
    // 合理
    setProblemListsuccess() {
      this.getProblemList = []
      for (var i = 0; i < this.getProblemListsuccess.length; i++) {
        this.getProblemList.push(this.getProblemListsuccess[i])
      }
    },
    // 不合理
    setProblemListdanger() {
      this.getProblemList = []
      for (var i = 0; i < this.getProblemListdanger.length; i++) {
        this.getProblemList.push(this.getProblemListdanger[i])
      }
    },
    // 合理不合理
    setAllgetProblemList() {
      this.getProblemList = []
      for (var i = 0; i < this.allgetProblemList.length; i++) {
        this.getProblemList.push(this.allgetProblemList[i])
      }
    },
    // 清空点评
    async DeleteProblem() {
      await DeleteProblem({
        Patient_Id: this.patientInfo.patient_id,
        Clinic_No: this.patientInfo.visitid,
        Presc_No: this.patientInfo.prescno,
        Hospital_Code: this.JsonValueTemp.Hospital_Code,
        templateId: this.JsonValueTemp.templateId
      }).then(res => {
        if (res.data === 1) {
          this.$message({
            message: '保存成功',
            type: 'success'
          })
          this.closeDialog()
        } else if (res.data === 0) {
          this.$message({
            message: '保存失败',
            type: 'error'
          })
        }
        this.GetProblemList()
      }).catch(err => {
        console.log(err)
      })
    },
    // 点评点
    async GetRules() {
      await GetRules({
        templateId: this.JsonValueTemp.templateId
      }).then(res => {
        this.getRules = res.data
      }).catch(err => {
        console.log(err)
      })
    },
    // 问题相关操作
    // 显示新增问题弹窗
    showAddVisible() {
      this.GetRules()
      this.addVisible = true
    },
    showAddVisibleFlag() {
      this.isAddFlag = '新增'
      this.showAddVisible()
    },
    closeAddVisible() {
      this.addVisible = false
      this.addInfo = {
        Drugname: '',
        RuleInfo: [],
        id: '',
        RuleInfoId: '',
        RuleInfoIs_Use: '',
        RuleInfoComments_Name: '',
        selectInfo: '',
        ManageviewTemp: '',
        Manageview: ''
      }
      this.getRules = []
    },
    // 选择点评点
    selectionChange(val) {
      this.RuleInfo = val
      const id = []
      const RuleInfoId = []
      const RuleInfoIs_Use = []
      const RuleInfoComments_Name = []
      for (var i = 0; i < this.RuleInfo.length; i++) {
        id[i] = this.RuleInfo[i].id
        RuleInfoId[i] = this.RuleInfo[i].commentsid
        RuleInfoIs_Use[i] = this.RuleInfo[i].is_use
        RuleInfoComments_Name[i] = this.RuleInfo[i].commentsname
      }
      this.addInfo.id = id.join(',')
      this.addInfo.RuleInfoId = RuleInfoId.join(',')
      this.addInfo.RuleInfoIs_Use = RuleInfoIs_Use.join(',')
      this.addInfo.RuleInfoComments_Name = RuleInfoComments_Name.join(',')
    },
    async GetCommentsID() {
      await GetCommentsID({
      }).then(res => {
        if (res.code === 200) {
          this.nextval = res.data[0].nextval
          this.SaveProblemList()
        }
      }).catch(err => {
        console.log(err)
      })
    },
    async SaveProblemList() {
      if (this.nextval != null) {
        const tempJson = {
          Hospital_Code: this.JsonValueTemp.Hospital_Code,
          ID: this.nextval,
          Patient_Id: this.patientInfo.patientid,
          Clinic_No: this.patientInfo.visitid,
          // Clinic_No: this.patientInfo.clinicno,
          Comments_User: this.UserName, //
          templateId: this.JsonValueTemp.templateId,
          DateTime: new Date().getFullYear() + '-' + (new Date().getMonth() + 1) + '-' + new Date().getDate(), // 	时间
          Presc_No: this.patientInfo.prescno,
          Comments_Mode: '0', // 	1系统点评 0自动点评
          Comments_Result: '0', // 1 合理 0不合理
          RuleId: this.addInfo.id, // 	点评点
          Is_Use: this.addInfo.RuleInfoIs_Use, // 是否开启
          Comments_Name: this.addInfo.RuleInfoComments_Name, // 	点评内容
          Comments_Username: this.UserName, // 	点评人
          Drugname: this.addInfo.Drugname, // 	药品
          Manageview: this.addInfo.Manageview // 意见
        }
        console.log(tempJson)
        await SaveProblemList({
          JsonValue: tempJson
        }).then(res => {
          if (res.code === 200) {
            this.$message({
              message: '保存成功',
              type: 'success'
            })
            this.GetProblemList()
          } else {
            this.$message({
              message: '保存失败',
              type: 'error'
            })
          }
          this.closeAddVisible()
        }).catch(err => {
          console.log(err)
        })
      } else {
        this.$message({
          message: '获取ID失败',
          type: 'error'
        })
      }
      this.closeAddVisible()
    },
    operateClickProblem(val, row) {
      this.problemInfo.RuleId = row.ruleid
      this.problemInfo.Id = row.id
      if (val === '修改') {
        this.isAddFlag = '修改'
        this.addInfo.Drugname = row.drugname
        this.addInfo.ManageviewTemp = row.manageview
        this.showAddVisible()
      } else if (val === '删除') {
        this.DeleteProblemList()
      }
      console.log(this.problemInfo)
    },
    async UpProblemList() {
      await UpProblemList({
        templateId: this.JsonValueTemp.templateId,
        RuleId: this.problemInfo.ruleid,
        DrugName: this.addInfo.Drugname,
        CommentsName: this.addInfo.Manageview,
        UserName: this.UserName,
        UserCode: this.UserCode,
        Id: this.problemInfo.Id
      }).then(res => {
        if (res.code === 200) {
          this.$message({
            message: '保存成功',
            type: 'success'
          })
          this.GetProblemList()
        } else {
          this.$message({
            message: '保存失败',
            type: 'error'
          })
        }
        this.closeAddVisible()
      }).catch(err => {
        console.log(err)
      })
    },
    async DeleteProblemList() {
      await DeleteProblemList({
        Id: this.problemInfo.Id
      }).then(res => {
        if (res.code === 200) {
          this.$message({
            message: '删除成功',
            type: 'success'
          })
          this.GetProblemList()
        } else {
          this.$message({
            message: '删除失败',
            type: 'success'
          })
        }
        this.GetProblemList()
      }).catch(err => {
        console.log(err)
      })
    }
  }
}
</script>

<style scoped lang="scss">
  body{
    background:#e6edf5;
  }
  .wrapper{
    width: 100%;
    height: 100%;
    font-size: 12px;
    .main-message{
      background-color: #E6EDF5;
      padding-left: 20px;
      .btn-layout{
        padding: 10px 0;
        .el-button{
          margin-right: 20px;
        }
      }
      .card-layout{
        display: flex;
        flex-wrap: wrap;
        .left{
          flex: 1;
          min-width: 540px;
          padding-right: 20px;
          padding-bottom: 20px;
        }
        .right{
          padding-right: 20px;
          min-width: 540px;
          flex: 1;
          .right-bottom{
            margin-top: 20px;
          }
        }
      }
    }
  }
  .content-item{
    display: flex;
    margin-bottom: 5px;
    .content-item-title{
      width: 80px;
      line-height: 40px;
      text-align: right;
    }
    .content-item-component{
      margin-left: 5px;
    }
    .content-item-component-checkbox{
      margin-left: 5px;
      line-height: 40px;
    }
    .content-item-component-radio{
      margin-left: 5px;
      line-height: 40px;
    }
    .content-item-btns{
      margin-left: 10px;
      display: flex;
      align-items: center;
      .el-button{
        width: 56px;
        height: 28px;
        margin-right: 10px;
      }
    }
  }
  .seek_pop{
    padding:0 20px;
    .seek_form{
      font-size:14px;
      line-height:40px;
      border:1px solid #b3d8ff;
      .seek_factor{
        width:25%;
        height:40px;
        display:flex;align-items: center;justify-content: center;
        .seek_text{
          display:inline-block;
          width:45%;
          height:100%;
          background:#ecf5ff;
          color:#409eff;
          text-align:right;
          padding-right:10px;
          overflow: hidden;
          text-overflow:ellipsis;
          white-space: nowrap;
        }
        .seek_val{
          display:inline-block;
          width:50%;
          height:100%;
          color:#333;
          padding-left:10px;
          overflow: hidden;
          text-overflow:ellipsis;
          white-space: nowrap;
        }
      }
    }
    .seek_tabs{
      margin-bottom:20px;
      height: 400px;
    }
    .card_result{
      margin-top: 10px;
      .seek_other{
        margin-bottom:20px;
        .btns{
          display: flex;
          justify-content: space-between;
          margin-bottom: 20px;
        }
      }
    }

  }
  // 滚动条
  /deep/.el-scrollbar__wrap {
    overflow-x: hidden;
  }
</style>
